import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../common/style/colors.dart';
import 'ink/ink_well_custom.dart';

/// @author zavier
/// @time 2023/7/8 16:06
/// @des 文本

class TextView extends StatelessWidget {
  /// 文本
  final String text;

  /// 字体大小
  final double? fontSize;

  /// 字体颜色
  final Color? fontColor;

  /// 字体权重
  final FontWeight? fontWeight;

  /// 内边距
  final EdgeInsets? padding;

  /// 左边图标
  final IconData? leftIcon;

  ///右边图标
  final IconData? rightIcon;

  /// 顶部图标
  final IconData? topIcon;

  /// 底部图标
  final IconData? bottomIcon;

  /// 图标大小
  final double? iconSize;

  /// 图标颜色
  final Color? iconColor;
  final int? maxLines;
  final TextOverflow? overflow;
  final TextDecoration? decoration;
  /// 点击事件
  final VoidCallback? onTap;

  const TextView({
    Key? key,
    required this.text,
    this.fontSize,
    this.padding,
    this.fontColor = AppColors.colorTextMain,
    this.fontWeight,
    this.leftIcon,
    this.rightIcon,
    this.topIcon,
    this.bottomIcon,
    this.iconSize,
    this.iconColor = AppColors.colorTextMain,
    this.onTap,
    this.maxLines,
    this.overflow,
    this.decoration,
  }) : super(key: key);

  Widget _getText() {
    return Text(
      text,
      maxLines: maxLines,
      overflow: overflow,
      style:
          TextStyle(color: fontColor ?? AppColors.colorTextMain, fontSize: fontSize ?? 14.sp, fontWeight: fontWeight,decoration: decoration),
    );
  }

  Widget _getLeftIcon() {
    return leftIcon == null
        ? const SizedBox()
        : Icon(
            leftIcon,
            size: iconSize,
            color: iconColor,
          );
  }

  Widget _getRightIcon() {
    return rightIcon == null
        ? const SizedBox()
        : Icon(
            rightIcon,
            size: iconSize,
            color: iconColor,
          );
  }

  Widget _getTopIcon() {
    return topIcon == null
        ? const SizedBox()
        : Icon(
            topIcon,
            size: iconSize,
            color: iconColor,
          );
  }

  Widget _getBottomIcon() {
    return bottomIcon == null
        ? const SizedBox()
        : Icon(
            bottomIcon,
            size: iconSize,
            color: iconColor,
          );
  }

  bool _hasIcon() {
    return topIcon != null || leftIcon != null || bottomIcon != null || rightIcon != null;
  }

  @override
  Widget build(BuildContext context) {
    return InkWellCustom(
      onTap: onTap,
      child: Container(
        padding: padding,
        child: _hasIcon()
            ? Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  _getTopIcon(),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [_getLeftIcon(), _getText(), _getRightIcon()],
                  ),
                  _getBottomIcon()
                ],
              )
            : _getText(),
      ),
    );
  }
}
